home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
shazam.exe
/
GDESKTOP.IMP
< prev
next >
Wrap
Text File
|
1992-09-01
|
17KB
|
483 lines
{*******************************************************************
GDESKTOP.IMP
*******************************************************************}
{===================================================================
HISTORY
===================================================================}
{-------------------------------------------------------------------
SAVE
-------------------------------------------------------------------}
procedure SaveHistory ( VAR S : TStream ) ;
var
Size : word ;
begin
if S.Status <> stOk then EXIT ;
Size := HistoryUsed
- PtrRec ( HistoryBlock ).Ofs ;
S.Write ( Size , SizeOf ( Word ) ) ;
S.Write ( HistoryBlock^ , Size ) ;
end ;
{-------------------------------------------------------------------
LOAD
-------------------------------------------------------------------}
procedure LoadHistory ( VAR S : TStream ) ;
var
Size : word ;
begin
if S.Status <> stOk then EXIT ;
S.Read ( Size , SizeOf ( Word ) ) ;
S.Read ( HistoryBlock^ , Size ) ;
if S.Status = stOk then
HistoryUsed := PtrRec ( HistoryBlock ).Ofs
+ Size
else
ClearHistory ;
end ;
{===================================================================
PALETTE - saves all three (3) palettes. Note that we do NOT want to
save the actual "AppPalette", since we would lose auto-detect. This
could happen when using dual monitors, changing from color to B&W or
vice-versa, and (no doubt) there are other possibilities.
To force a palette, use command-line switches and call hdColor,
hdBlackWhite or hdMonochrome AFTER application starts.
===================================================================}
{-------------------------------------------------------------------
SAVE
-------------------------------------------------------------------}
procedure SavePalette ( VAR S : TStream ) ;
var
SaveAppPalette : integer ;
P : PString ;
begin
if S.Status <> stOk then EXIT ;
SaveAppPalette := AppPalette ;
for AppPalette := apColor to apMonochrome do
begin
P := NewStr ( Application^.GetPalette^ ) ;
S.WriteStr ( P ) ;
DisposeStr ( P ) ;
end ;
AppPalette := SaveAppPalette ;
end ;
{-------------------------------------------------------------------
LOAD
-------------------------------------------------------------------}
procedure LoadPalette ( VAR S : TStream ) ;
var
SaveAppPalette : integer ;
P : PString ;
begin
if S.Status <> stOk then EXIT ;
SaveAppPalette := AppPalette;
for AppPalette := apColor to apMonochrome do
begin
P := S.ReadStr ;
Application^.GetPalette^ := TPalette ( P^ ) ;
DisposeStr ( P ) ;
end ;
AppPalette := SaveAppPalette ;
if S.Status <> stOk then
hdResetColors ;
hdRefreshDisplay ;
end ;
{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DESKTOP - Must apply TEditor Load/Store patch!
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
{===================================================================
STORE
===================================================================}
procedure DesktopWriteViews ( VAR S : TStream ) ;
{-------------------------------------------------------------------
IF VISIBLE
-------------------------------------------------------------------}
procedure WriteView ( P : PView ) ; FAR ;
begin
if P = Desktop^.Last then EXIT ;
if P^.GetState ( sfVisible ) then
S.Put ( P ) ;
end ;
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PROCESS
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
begin
if S.Status <> stOk then EXIT ;
Desktop^.ForEach ( @WriteView ) ;
S.Put ( NIL ) ;
end ;
{===================================================================
LOAD - One at a time; "ValidView" calls "OutOfMemory" if LowMemory
is TRUE.
NOTE: Default "OutOfMemory" does nothing - should be overridden.
===================================================================}
procedure DesktopReadViews ( VAR S : TStream ) ;
var
P : PView ;
begin
if S.Status <> stOk then EXIT ;
while TRUE do
begin
P := PView ( S.Get ) ;
Desktop^.InsertBefore ( Application^. ValidView ( P ) ,
Desktop^.Last ) ;
if P = NIL then EXIT ;
end ;
end ;
{===================================================================
SAVE
===================================================================}
procedure SaveDesktopTo ( FileName : PathStr ; Description : string ) ;
var
Strm : PStream ;
begin
if FileName = '' then EXIT ;
SaveEdUntitled ; { save, or }
CloseEdUntitled ; { dump empties }
SaveEdModified ; { keep changes }
Strm := New ( PDosStream ,
Init ( FileName ,
stCreate ) ) ;
Description := Description + #26 ;
Strm^.Write ( Description[1] , length ( Description ) ) ;
Strm^.Write ( VersionCode[0] , length ( VersionCode ) + 1 ) ;
SaveHistory ( Strm^ ) ;
SavePalette ( Strm^ ) ;
DesktopWriteViews ( Strm^ ) ;
if Strm^.Status <> stOk then
begin
FileErase ( FileName ) ;
MessageBox ( ^C'Could not create'#13
+ FileName ,
NIL ,
mfError + mfOkButton ) ;
end ;
Dispose ( Strm , Done ) ;
end ;
{===================================================================
LOAD
===================================================================}
procedure LoadDesktopFrom ( FileName : PathStr ) ;
var
Strm : PStream ;
VersionCodeTest : string ;
Ch : char ;
begin
if not FileExist ( FileName ) then EXIT ;
CloseAll ;
Strm := New ( PDosStream ,
Init ( FileName ,
stOpenRead ) ) ;
Ch := #0 ;
while ( Ch <> ^Z ) and ( Strm^.Status = stOK ) do
Strm^.Read ( Ch , 1 ) ;
Strm^.Read ( VersionCodeTest [0] , 1 ) ;
Strm^.Read ( VersionCodeTest [1] , length ( VersionCode ) ) ;
if VersionCode = VersionCodeTest then
begin
LoadHistory ( Strm^ ) ;
LoadPalette ( Strm^ ) ;
DesktopReadViews ( Strm^ ) ;
end
else
begin
Strm^.Seek ( 0 ) ;
Strm^.Truncate ;
Strm^.Reset ;
if Application <> NIL then
MessageBox ( ^C'DESKTOP version change to ' + VersionCode ,
NIL ,
mfWarning + mfOKButton ) ;
end ;
if Strm^.Status <> stOk then
MessageBox ( ^C'Error reading desktop file'#13
+ FileName ,
NIL ,
mfError + mfOkButton ) ;
Dispose ( Strm , Done ) ;
end ;
{|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
EVENT
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
{===================================================================
COMMAND - easy way to pass commands
===================================================================}
procedure CommandAll ( Command : word ) ;
{-------------------------------------------------------------------
Send command
---------------------------------------------------